Example 4:

In the above plots of sin(x), it would make more sense to label the axis in units of π. The position and labels of the tic labels may be specified by the user, with the set xtics and set ytics commands. This is demonstrated by the following example, shown in Figure [*].

    set terminal latex
    set output "eg4.tex"
    set format y "$%g$"
    set format x "$%.2f$"
    set title "This is $\sin(x)$"
    set xlabel "This is the $x$ axis"
    set ylabel "$\sin(x)$"
    set nokey
    set xtics -pi, pi/4
    plot [-pi:pi] [-1:1] sin(x)

htbp

\begin{center}\vbox{\input{eg4}
}\end{center}

Since pi is a predefined variable in GNUPLOT, we can use it anywhere we may use an expression. The set xtics command here specifies that the tics on the x axis start at - π and increment by π/4. Since no end point is given, the tics continue to the right edge. We have also turned off the key, and changed the format to restrict the x-axis tic labels to 2 decimal places.

With a little more work, the plot can look even better. Another form of this command allows us to specify the label and position of each tic individually. Replacing the above set xtics command with the following gives us Figure [*]. We also make use of the line continuation character, the backslash (\), to spread out this command for readability.

    set xtics ("$-\pi$" -pi,\
     "$-\frac{\pi}{2}$" -pi/2,\
     "0" 0,\
     "$\frac{\pi}{2}$" pi/2,\
     "$\pi$" pi)

htbp

\begin{center}\vbox{\input{eg5}
}\end{center}